package com.jvyou.driver.controller;

import com.jvyou.driver.domain.entity.SysFile;
import com.jvyou.driver.domain.modal.Result;
import com.jvyou.driver.service.SysFileService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import cn.dev33.satoken.annotation.SaCheckPermission;

/**
 * 文件表(SysFile)表控制层
 *
 * @author 橘柚
 * @since 2025-04-10 10:58:23
 */
@RestController
@RequestMapping("/sysFile")
@AllArgsConstructor
public class SysFileController  {
    
    private SysFileService sysFileService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("/{id}")
    @SaCheckPermission("dw:sysFile:get")
    public Result<SysFile> selectOne(@PathVariable Long id) {
        return Result.success(sysFileService.getById(id));
    }

    /**
     * 新增数据
     *
     * @param sysFile 实体对象
     * @return 新增结果
     */
    @PostMapping
    @SaCheckPermission("dw:sysFile:insert")
    public Result<SysFile> insert(@RequestBody SysFile sysFile) {
        boolean success = sysFileService.save(sysFile);
        return success ? Result.success(sysFile) : Result.error(HttpCodeEnum.ADD_FAIL);
    }
    
     /**
     * 修改数据
     *
     * @param sysFile 实体对象
     * @return 修改结果
     */
    @PutMapping("/updateById")
    @SaCheckPermission("dw:sysFile:update")
    public Result<SysFile> updateById(@RequestBody SysFile sysFile) {
        boolean success = sysFileService.updateById(sysFile);
        return success ? Result.success(sysFile) : Result.error(HttpCodeEnum.UPDATE_FAIL);
    }
    

    /**
     * 删除数据
     *
     * @param id 主键结合
     * @return 删除结果
     */
    @DeleteMapping("/{id}")
    @SaCheckPermission("dw:sysFile:delete")
    public Result<Boolean> delete(@PathVariable Long id) {
        boolean success = sysFileService.removeById(id);
        return success ? Result.success(true) : Result.error(HttpCodeEnum.DELETE_FAIL);
    }
    
}

